﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Framework.MVC;
using Billing.IService.Entry;
using Billing.Models;
using Common.IService.Entry;

namespace Billing.Controllers
{
    public class RechargeController : AsyncControllerBase
    {
        #region Get

        public void GetAsync(string orderCode, string sourceCode)
        {
            GetRechargeModel model = new GetRechargeModel
            {
                OrderCode = orderCode,
                OrderSource = sourceCode,
                Source = Request.UserHostAddress,
                ConfigName = "filter:ip:recharge:end"
            };
            InitModel(model);
        }

        public ActionResult GetCompleted(OrderEntry entry)
        {
            return entry == null ? null : Json(entry);
        }

        #endregion Get

        #region New

        public void NewAsync(string orderCode, string sourceCode, decimal? amount,string owner)
        {
            NewRechargeModel model = new NewRechargeModel
            {
                OrderCode = orderCode,
                OrderOwner = owner,
                OrderSource = sourceCode,
                OrderAmount = amount == null ? decimal.Zero : amount.Value,
                Source = Request.UserHostAddress,
                ConfigName = "filter:ip:recharge:end"
            };
            InitModel(model);
        }

        public ActionResult NewCompleted(OrderEntry entry)
        {
            return entry == null ? null : Json(entry);
        }

        #endregion New

        #region End

        public void EndAsync(string orderCode, string sourceCode, decimal? amount)
        {
            EndRechargeModel model = new EndRechargeModel
            {
                OrderCode = orderCode,
                OrderSource = sourceCode,
                Amount = amount == null ? decimal.Zero : amount.Value,
                Source = Request.UserHostAddress,
                ConfigName = "filter:ip:recharge:end"
            };
            InitModel(model);
        }

        public ActionResult EndCompleted(byte result)
        {
            return Content(result.ToString());
        }

        #endregion End

        #region Query

        public void QueryPageAsync(string user, string resource,string begin,string end,int page,int size)
        {
            QueryPageRechargeModel model = new QueryPageRechargeModel
            {
                OrderSourceCode=resource,
                OrderUser=user,
                BeginTime = begin,
                EndTime = end,
                PageIndex = page,
                PageSize = size,
                Source = Request.UserHostAddress,
                ConfigName = "filter:ip:recharge:end"
            };
            InitModel(model);
        }

        public ActionResult QueryPageCompleted(int count,OrderEntry[] data)
        {
            return Json(new QueryPageEntry<OrderEntry> { Count = count, Data = data });
        }

        #endregion Query

        #region Validate

        public void ValidateAsync(string orderCode, string sourceCode, decimal? amount, string owner, byte status)
        {
            ValidateRechargeModel model = new ValidateRechargeModel
            {
                OrderCode = orderCode,
                OrderSource = sourceCode,
                Onwer = owner,
                Amount = amount == null ? decimal.Zero : amount.Value,
                Status = status,
                Source = Request.UserHostAddress,
                ConfigName = "filter:ip:recharge:end"
            };
            InitModel(model);
        }

        public ActionResult ValidateCompleted(bool result)
        {
            return Content(result.ToString());
        }

        #endregion Validate
    }
}
